import {WeaSearchGroup, WeaFormItem, WeaLocaleProvider} from 'ecCom';
import {WeaSwitch} from 'comsMobx';
import { Button } from 'antd';
const getLabel = WeaLocaleProvider.getLabel;
class Condition extends React.Component{
    formParams = {};
    render(){
        const { condition, form } = this.props.listStore;
        const {isFormInit} = form;
        let group = [];
        const fixedFormParamsTemp = form.getFormParams();
        for(let param in fixedFormParamsTemp){
            this.formParams[param] = fixedFormParamsTemp[param];
        }
        isFormInit && condition.map((c,index) =>{
            let items = [];
            c.items.map(fields => {
                items.push({
                    com:(<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@p9o5lz@${fields.domkey[0]}`}
                        label={`${fields.label}`}
                        labelCol={{span: `${fields.labelcol}`}}
                        wrapperCol={{span: `${fields.fieldcol}`}}>
                        <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@8knn7a@${fields.domkey[0]}`} fieldConfig={fields} form={form} formParams={this.formParams}/>
                    </WeaFormItem>),
                    colSpan:1
                })
            });
            group.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@wwvizr@${index}`} needTigger={true} title={c.title} showGroup={c.defaultshow} items={items}/>)
        });
        return <div>{group}</div>;
    }
}

const getAdButtons = (listStore, ecId) => {
    const {doSearch,setShowSearchAd,clearFormFields} = listStore;
    return [
        (<Button ecId={`${ecId}_Button@pm4mbx@search`} type="primary" onClick={()=>{doSearch();setShowSearchAd(false);}}>{getLabel(197,'搜索')}</Button>), //添加注释 强编译
        (<Button ecId={`${ecId}_Button@4dedqg@reset`} type="ghost" onClick={()=>{clearFormFields()}}>{getLabel(2022,'重置')}</Button>),
        (<Button ecId={`${ecId}_Button@l4cwv9@cancel`} type="ghost" onClick={()=>{setShowSearchAd(false)}}>{getLabel(201,'取消')}</Button>)
    ];
}

export {Condition,getAdButtons}
